<?php
session_start();
include("load-settings.php");

if(!isset($_SESSION['user']))
	header("Location: login.php");

$user = mysql_real_escape_string($_SESSION['user']);
$result = mysql_query("SELECT * FROM user WHERE id = $user");
$row = mysql_fetch_array($result);

if($row['type'] != 2)
	header("Location: home.php");
?>
<!doctype html>
<html>
<head>
  <meta charset="UTF-8" />
  <meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=0">

  <!-- Always force latest IE rendering engine or request Chrome Frame -->
  <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <link rel="icon" href="http://www.veteranboosters.com/wp-content/uploads/2014/04/favicon4.png" type="image/x-icon"/>
    <link rel="shortcut icon" href="http://www.veteranboosters.com/wp-content/uploads/2014/04/favicon4.png" type="image/x-icon"/>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,600,800">

  <!-- Use title if it's in the page YAML frontmatter -->
  <title>Veteran Boosters Order Tracking</title>


  <!--[if lt IE 9]>
  <script src="../../javascripts/vendor/html5shiv.js" type="text/javascript"></script>
  <script src="../../javascripts/vendor/excanvas.js" type="text/javascript"></script>
  <![endif]-->
<link rel="stylesheet" href="css/bootstrap.min.css" />
<link rel="stylesheet" href="css/font-awesome.css" />
<link rel="stylesheet" href="css/fullcalendar.css" />
<link rel="stylesheet" href="css/jquery.jscrollpane.css" />	
<link rel="stylesheet" href="css/unicorn.css" />
  <link href="stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />
  <script src="javascripts/application.js" type="text/javascript"></script>
  <script>
  function check_order (event)
  {
		var form = document.getElementById("new_order_form");

		var wins = form.goal.value;
		var end_tier = form.end_tier.value;
		var end_division = form.end_division.value;
		var start_tier = form.start_tier.value;
		var start_division = form.start_division.value;
      var payout = form.payout.value;
      var booster_payout = form.booster_payout.value;

      if(isNaN(wins) == true){
          alert("Please enter number of wins");
          event.preventDefault();
          return false;
      }

      if(isNaN(booster_payout) == true){
          alert("Booster paid must be number type");
          event.preventDefault();
          return false;
      }

      if(isNaN(payout) == true){
          alert("Please enter Customer paid number");
          event.preventDefault();
          return false;
      }
		if(wins == "" && end_tier == "" )
		{
			alert("Please enter either number of wins or desired tier and division.");
			event.preventDefault();
			return false;
		}
		else if(wins != "" && end_tier != "")
		{
			alert("Please enter either number of wins or desired tier and division, but not both.");
			event.preventDefault();
			return false;
		}
		else if((end_tier == "" && end_division != "") || (end_tier != "" && end_division == ""))
	    {
			console.log(end_tier);
			console.log(end_division);
			alert("Desired tier and division must be filled out for division orders.");
			event.preventDefault();
			return false;
		}
		else if(start_division == "0" && start_tier != "Unranked" && start_tier != "Challenger")
	    {
			alert("Invalid start tier/division combination");
			event.preventDefault();
			return false;
	    }
		else
	    {
			return true;
		}
  }
  </script>
</head>

<?php
	include("top.php");
?>

<style>
    input{

    }
</style>
  <div class="container-fluid padded">
    <div class="row-fluid">

      <!-- Breadcrumb line -->

      <div id="breadcrumb">
	     <a href="/" title="" class="tip-bottom" data-original-title="Go to Home"><i class="fa fa-home"></i> Home</a>
		<a href="#">Members</a>
		<a href="#" class="current">View and edit orders      </a>
		
            </div>
    </div>
  </div>

  <div class="container-fluid padded">

<div class="row-fluid">
    <div class="span12">
        <div class="box">
            <div class="box-header">
                <span class="title">Create Orders</span>
            </div>
            <div class="box-content table-responsive">
                <table class="table ">
                    <thead>
                        <tr>
							<th>Customer paypal</th>
							<th>Summoner</th>
							<th>Username</th>
							<th>Password</th>
							<th>Region</th>
                            <th>Wins</th>
                            <th>Start tier</th>
                            <th>Start division</th>
                            <th>End tier</th>
                            <th>End division</th>
                            <th>Customer paid</th>
                            <th>Booster paid</th>
                            <th>Actions</th>
                        </tr>
                    </thead>
                    <tbody>
                        <form id = "new_order_form" onsubmit = "check_order(event)" action="new-order.php" method="post">
                        <tr>
							<td>
								<input name = "paypal" type = "text" style="width: 70px; margin-bottom: 0px;" />
							</td>
							<td>
								<input name = "summoner" type = "text" style="width: 70px; margin-bottom: 0px;" />
							</td>
							<td>
								<input name = "username" type = "text" style="width: 70px; margin-bottom: 0px;" />
							</td>
							<td>
								<input name = "password" type = "text" style="width: 70px; margin-bottom: 0px;" />
							</td>
							<td>
								<select name="region" style="width: 70px; margin-bottom: 0px">
									<option style="width: 70px" value="na">North America</option>
									<option  style="width: 70px"value="br">Brazil</option>
									<option  style="width: 70px"value="lan">Latin America North</option>
									<option  style="width: 70px"value="euw">Europe West</option>
									<option  style="width: 70px"value="eun">Europe East</option>
									<option style="width: 70px" value="ru">Russia</option>
									<option  style="width: 70px"value="tr">Turkey</option>
								</select>
							</td>
                            <td>
                                <input style="width: 25px; margin-bottom: 0px;" name="goal" type="text">
                            </td>
                            <td>
                                <select name="start_tier" style="width: 70px; margin-bottom: 0px;">
									<option  style="width: 70px">Unranked</option>
                                    <option  style="width: 70px">Bronze</option>
                                    <option  style="width: 70px">Silver</option>
                                    <option  style="width: 70px">Gold</option>
                                    <option  style="width: 70px">Platinum</option>
                                    <option  style="width: 70px">Diamond</option>
                                    <option  style="width: 70px">Challenger</option>
                                </select>
                            </td>
                            <td>
                                <select name="start_division" style="width: 70px; margin-bottom: 0px;">
                                    <option >1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option>5</option>
									<option value = '0' selected="selected">N/A</option>
                                </select>
                            </td>
                            <td>
                                <select name="end_tier" style="width: 70px; margin-bottom: 0px;">
                                    <option selected="selected" value="">N/A</option>
                                    <option>Bronze</option>
                                    <option>Silver</option>
                                    <option>Gold</option>
                                    <option>Platinum</option>
                                    <option>Diamond</option>
                                    <option>Challenger</option>
                                </select>
                            </td>
                            <td>
                                <select name="end_division" style="width: 70px; margin-bottom: 0px;">
                                    <option selected="selected" value="">N/A</option>
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option>5</option>
                                </select>
                            </td>
                            <td>
                                <input name="payout" style="width: 50px; margin-bottom: 0px;" >
                            </td>
                            <td>
                                <input name="booster_payout" style="width: 50px; margin-bottom: 0px;" >
                            </td>
                            <td>
                                <button type="submit" class=" btn btn-success btn-xs" value="">Create</button>
                            </td>
                        </tr>
						</form>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>

  <div class="row-fluid" style = "overflow: auto">
   <div class="col-lg-12" style = "min-width: 1520px">
      <div class="box">
         <div class="box-header">
            <span class="title">Boosting Orders</span>
         </div>
         <div class="box-content">
            <table style="" class="table table-bordered table-striped table-hover">
               <thead>
                  <tr>
					 <td style="width: 40px">ID</td>
					 <td style="width: 40px">Buyer</td>
                     <td style="">Booster</td>
					 <td style="width: 40px ">Summoner</td>
					 <td style=" ">Region</td>
					 <td style="width: 40px ">Username</td>
					 <td style=" width: 40px">Password</td>
                     <td style=" width: 40px">Wins</td>
                     <td style=" width: 40px">Losses</td>
					 <td style=" width: 40px">Goal</td>
					 <td style=" ">Start tier</td>
					 <td style=" ">Start division</td>
					 <td style=" ">End tier</td>
					 <td style=" ">End division</td>
					 <td style=" ">Status</td>
					 <td style=" ">Starting stats</td>
					 <td style=" ">Customer paid</td>
					 <td style=" ">Booster paid</td>
					 <td style=" ">Actions</td>
                  </tr>
               </thead>
               <tbody>
			   <?php
					$result = mysql_query("SELECT * FROM order_record WHERE complete = 0");

					if(mysql_num_rows($result) == 0)
					{
						echo "<tr><td colspan='4'>You don't have any orders.</td></tr>";
					}
					else
					{
						$boosters = array();

						$booster_result = mysql_query("SELECT * FROM user WHERE type = 1 OR type = 2 ORDER BY username");
						
						while($booster_row = mysql_fetch_array($booster_result))
						{
							array_push($boosters, $booster_row);
						}

						while($row = mysql_fetch_array($result))
						{
							$booster_select = "<select name = 'booster' style = 'width: 70px; margin-bottom: 0px;'>";
							
							$x = 0;

							$subresult = mysql_query("SELECT * FROM booster_order WHERE active <> 0 AND order_record = ".$row['id']);

							if(mysql_num_rows($subresult) == 0)
							{
								$wins = 0;
								$losses = 0;
								$status = "Pending";
								$booster_select .= "<option selected = 'selected'>None</option>";
								$subrow = array();
								$subrow['booster'] = "none";
								$subrow['active'] = 1;
							}
							else
							{
								$subrow = mysql_fetch_array($subresult);
								$wins = $subrow['wins'];
								$losses = $subrow['losses'];

								if($subrow['active'] == 0)
									$status = "Complete";
								else if($subrow['active'] == 1)
									$status = "Active";
								else if($subrow['active'] == 2)
									$status = "Paused";
								else if($subrow['active'] == 3)
									$status = "Admin reviewing";

								$booster_select .= "<option>None</option>";
							}

							while(isset($boosters[$x]))
							{
								if($subrow['booster'] == $boosters[$x]['id'])
								{
									$booster_select .= "<option value = '".$boosters[$x]['id']."' selected = 'selected'>".$boosters[$x]['username']."</option>";
								}
								else
									$booster_select .= "<option value = '".$boosters[$x]['id']."'>".$boosters[$x]['username']."</option>";
								$x++;
							}
							$booster_select .= "</select>";

							if($row['number_of_wins'] != null && $row['number_of_wins'] != '')
								$goal = $row['number_of_wins'];
							else
								$goal = "";

							if($row['end_tier'] != null && $row['end_tier'] != '')
							{
								$end_tier = $row["end_tier"];
								$end_division = $row["end_division"];
							}
							else
							{
								$end_tier = "";
								$end_division = "";
							}

							$start_tier_select = "<select name = 'start_tier' style='width: 70px; margin-bottom: 0px;'>";

							if($row['start_tier'] == "Unranked")
								$start_tier_select .= "<option selected = 'selected'>Unranked</option>";
							else
								$start_tier_select .= "<option>Unranked</option>";

							if($row['start_tier'] == "Bronze")
								$start_tier_select .= "<option selected = 'selected'>Bronze</option>";
							else
								$start_tier_select .= "<option>Bronze</option>";

							if($row['start_tier'] == "Silver")
								$start_tier_select .= "<option selected = 'selected'>Silver</option>";
							else
								$start_tier_select .= "<option>Silver</option>";

							if($row['start_tier'] == "Gold")
								$start_tier_select .= "<option selected = 'selected'>Gold</option>";
							else
								$start_tier_select .= "<option>Gold</option>";

							if($row['start_tier'] == "Platinum")
								$start_tier_select .= "<option selected = 'selected'>Platinum</option>";
							else
								$start_tier_select .= "<option>Platinum</option>";

							if($row['start_tier'] == "Diamond")
								$start_tier_select .= "<option selected = 'selected'>Diamond</option>";
							else
								$start_tier_select .= "<option>Diamond</option>";

							if($row['start_tier'] == "Challenger")
								$start_tier_select .= "<option selected = 'selected'>Challenger</option>";
							else
								$start_tier_select .= "<option>Challenger</option>";

							$start_division_select = "<select name = 'start_division' style='width: 70px; margin-bottom: 0px;'>";

							if($row['start_division'] == 1)
								$start_division_select .= "<option selected = 'selected'>1</option>";
							else
								$start_division_select .= "<option>1</option>";

							if($row['start_division'] == 2)
								$start_division_select .= "<option selected = 'selected'>2</option>";
							else
								$start_division_select .= "<option>2</option>";

							if($row['start_division'] == 3)
								$start_division_select .= "<option selected = 'selected'>3</option>";
							else
								$start_division_select .= "<option>3</option>";

							if($row['start_division'] == 4)
								$start_division_select .= "<option selected = 'selected'>4</option>";
							else
								$start_division_select .= "<option>4</option>";

							if($row['start_division'] == 5)
								$start_division_select .= "<option selected = 'selected'>5</option>";
							else
								$start_division_select .= "<option>5</option>";

							if($row['start_division'] == 0)
								$start_division_select .= "<option value = '0' selected='selected'>N/A</option>";
							else
								$start_division_select .= "<option value = '0'>N/A</option>";

							

							$end_tier_select = "<select name = 'end_tier' style='width: 70px; margin-bottom: 0px;'>";

							if($end_tier == "")
								$end_tier_select .= "<option selected = 'selected' value = ''>N/A</option>";
							else
								$end_tier_select .= "<option value = ''>N/A</option>";

							if($end_tier == "Bronze")
								$end_tier_select .= "<option selected = 'selected'>Bronze</option>";
							else
								$end_tier_select .= "<option>Bronze</option>";

							if($end_tier == "Silver")
								$end_tier_select .= "<option selected = 'selected'>Silver</option>";
							else
								$end_tier_select .= "<option>Silver</option>";

							if($end_tier == "Gold")
								$end_tier_select .= "<option selected = 'selected'>Gold</option>";
							else
								$end_tier_select .= "<option>Gold</option>";

							if($end_tier == "Platinum")
								$end_tier_select .= "<option selected = 'selected'>Platinum</option>";
							else
								$end_tier_select .= "<option>Platinum</option>";

							if($end_tier == "Diamond")
								$end_tier_select .= "<option selected = 'selected'>Diamond</option>";
							else
								$end_tier_select .= "<option>Diamond</option>";

							if($end_tier == "Challenger")
								$end_tier_select .= "<option selected = 'selected'>Challenger</option>";
							else
								$end_tier_select .= "<option>Challenger</option>";

							$end_division_select = "<select name = 'end_division' style='width: 70px; margin-bottom: 0px;'>";

							if($end_division == "")
								$end_division_select .= "<option selected = 'selected' value = ''>N/A</option>";
							else
								$end_division_select .= "<option value = ''>N/A</option>";

							if($end_division == 1)
								$end_division_select .= "<option selected = 'selected'>1</option>";
							else
								$end_division_select .= "<option>1</option>";

							if($end_division == 2)
								$end_division_select .= "<option selected = 'selected'>2</option>";
							else
								$end_division_select .= "<option>2</option>";

							if($end_division == 3)
								$end_division_select .= "<option selected = 'selected'>3</option>";
							else
								$end_division_select .= "<option>3</option>";

							if($end_division == 4)
								$end_division_select .= "<option selected = 'selected'>4</option>";
							else
								$end_division_select .= "<option>4</option>";

							if($end_division == 5)
								$end_division_select .= "<option selected = 'selected'>5</option>";
							else
								$end_division_select .= "<option>5</option>";

							$status_select = "<select name = 'status' style='width: 70px; margin-bottom: 0px;'>";

							if($subrow['active'] == 0)
								$status_select .= "<option value = '0' selected = 'selected'>Complete</option>";
							else
								$status_select .= "<option value = '0'>Complete</option>";

							if($subrow['active'] == 1)
								$status_select .= "<option value = '1' selected = 'selected'>Active</option>";
							else
								$status_select .= "<option value = '1'>Active</option>";

							if($subrow['active'] == 2)
								$status_select .= "<option value = '2' selected = 'selected'>Paused</option>";
							else
								$status_select .= "<option value = '2'>Paused</option>";

							if($subrow['active'] == 3)
								$status_select .= "<option value = '3' selected = 'selected'>Reviewing</option>";
							else
								$status_select .= "<option value = '3'>Reviewing</option>";

							$status_select .= "</select>";

							$region_select = "<select name = 'region' style='width: 70px; margin-bottom: 0px;'>";

							if($row['region'] == "na")
								$region_select .= "<option value = 'na' selected = 'selected'>North America</option>";
							else
								$region_select .= "<option value = 'na'>North America</option>";

							if($row['region'] == "br")
								$region_select .= "<option value = 'br' selected = 'selected'>Brazil</option>";
							else
								$region_select .= "<option value = 'br'>Brazil</option>";

							if($row['region'] == "lan")
								$region_select .= "<option value = 'lan' selected = 'selected'>Latin America North</option>";
							else
								$region_select .= "<option value = 'lan'>Latin America North</option>";

							if($row['region'] == "euw")
								$region_select .= "<option value = 'euw' selected = 'selected'>Europe West</option>";
							else
								$region_select .= "<option value = 'euw'>Europe West</option>";

							if($row['region'] == "eun")
								$region_select .= "<option value = 'eun' selected = 'selected'>Europe East</option>";
							else
								$region_select .= "<option value = 'eun'>Europe East</option>";

							if($row['region'] == "ru")
								$region_select .= "<option value = 'ru' selected = 'selected'>Russia</option>";
							else
								$region_select .= "<option value = 'ru'>Russia</option>";

							if($row['region'] == "tr")
								$region_select .= "<option value = 'na' selected = 'selected'>Turkey</option>";
							else
								$region_select .= "<option value = 'na'>Turkey</option>";

							$region_select .= "</select>";

							echo "<form action = 'change-order.php' method = 'post'>
							<input name = 'order_num' value = '".$row['id']."' type = 'hidden' />";
							echo "<tr><td style=' width:40px'>".$row['id']."</td>";
							echo "<td style = 'width:40px'><input name = 'buyer' style = 'margin-bottom: 0px; width: 25px;' value = '".$row['user']."' /></td>";
							echo "<td  style=' width:70px'>".$booster_select."</td>";
							echo "<td style='width:40px '><input style = 'width:25px; margin-bottom: 0px;' name = 'summoner' value = '".$row['summoner']."' /></td>";
							echo "<td style=' width:70px'>".$region_select."</td>";
							echo "<td style='width:40px '><input style = 'width:25px; margin-bottom: 0px;' name = 'username' value = '".$row['username']."' /></td>";
							echo "<td style='width:40px '><input style = ' width:25px;margin-bottom: 0px;' name = 'password' value = '".$row['password']."' /></td>";
							echo "<td style='width:40px '><input style = 'width: 25px; margin-bottom: 0px;' name = 'wins' type = 'text' value = '".$wins."' /></td>";
							echo "<td style='width:40px '><input style = 'width: 25px; margin-bottom: 0px;' name = 'losses' type = 'text' value = '".$losses."' /></td>";
							echo "<td style=' width:40px'><input style = 'width: 25px; margin-bottom: 0px;' name = 'goal' type = 'text' value = '".$goal."' /></td>";
							echo "<td  style='width:70px '>".$start_tier_select."</td>";
							echo "<td  style='width:70px '>".$start_division_select."</td>";
							echo "<td  style='width:70px '>".$end_tier_select."</td>";
							echo "<td  style='width:70px '>".$end_division_select."</td>";
							echo "<td  style='width:70px '>".$status_select."</td>";
							echo "<td  style='width:40px '><input name = 'beginning_stats' style = 'width:25px;margin-bottom: 0px;;' value = '".$row['beginning_stats']."' /></td>";
							echo "<td  style='width:40px '><input name = 'payout' style = ' width:40px;margin-bottom: 0px;' value = '".$row['payout']."' /></td>";
							echo "<td  style='width:40px '><input name = 'booster_payout' style = 'width:25px; margin-bottom: 0px;' value = '".$row['booster_payout']."' /></td>";
							echo "<td  style=''>
							<button style='margin-right:7px' type = 'submit' class=' btn btn-success btn-xs' />Update</button><a href = 'delete_order.php?id=".$row['id']."' class = ' btn btn-success btn-xs' onclick = 'check_confirm(event)'>Delete</a></td></tr></form>";
						}
					}
					
				?>
			   </tbody>
            </table>
         </div>
      </div>
   </div>
</div>
<!--
<div class="row-fluid">
    <div class="col-lg-12" style="min-width: 1050px">
        <div class="box">
            <div class="box-header">
                <span class="title">Create Duo Queue Orders</span>
            </div>
            <div class="box-content">
                <table class="table table-bordered table-striped table-hover">
                    <thead>
                        <tr>
							<td>Customer Paypal</td>
                            <td>Summoner</td>
							<td>Timezone</td>
							<td>Region</td>
							<td>Games needed</td>
							<td>Wins needed</td>
							<td>Coaches needed</td>
                            <td>Start tier</td>
                            <td>Start division</td>
                            <td>Customer paid</td>
                            <td>Booster paid</td>
                            <td>Actions</td>
                        </tr>
                    </thead>
                    <tbody>
					<form action="new-duo-order.php" method="post">
                        <tr>
							<td>
								<input name = "paypal" type = "text" style="width: 40px; margin-bottom: 0px;" />
							</td>
							<td>
								<input name = "summoner" type = "text" style="width: 40px; margin-bottom: 0px;" />
							</td>
							<td>
								<input name = "timezone" type = "text" style="width: 40px; margin-bottom: 0px;" />
							</td>
							<td>
								<select name="region" style="width: 70px; margin-bottom: 0px">
									<option value="na">North America</option>
									<option value="br">Brazil</option>
									<option value="lan">Latin America North</option>
									<option value="euw">Europe West</option>
									<option value="eun">Europe East</option>
									<option value="ru">Russia</option>
									<option value="tr">Turkey</option>
								</select>
							</td>
                            <td>
                                <input style="width: 25px; margin-bottom: 0px;" name="games_needed" type="text">
                            </td>
							<td>
                                <input style="width: 25px; margin-bottom: 0px;" name="wins_needed" type="text">
                            </td>
							<td>
                                <input style="width: 25px; margin-bottom: 0px;" name="coaches_needed" type="text">
                            </td>
                            <td>
                                <select name="start_tier" style="width: 70px; margin-bottom: 0px;">
                                    <option selected="selected">Bronze</option>
                                    <option>Silver</option>
                                    <option>Gold</option>
                                    <option>Platinum</option>
                                    <option>Diamond</option>
                                    <option>Challenger</option>
                                </select>
                            </td>
                            <td>
                                <select name="start_division" style="width: 70px; margin-bottom: 0px;">
                                    <option>1</option>
                                    <option>2</option>
                                    <option>3</option>
                                    <option>4</option>
                                    <option selected="selected">5</option>
                                </select>
                            </td>
                            <td>
                                <input name="payout" style="width: 50px; margin-bottom: 0px;" >
                            </td>
                            <td>
                                <input name="booster_payout" style="width: 50px; margin-bottom: 0px;" >
                            </td>
                            <td>
                                <button type="submit" class=" btn btn-success btn-xs" value="">Create</button>
                            </td>
                        </tr>
						</form>
					</tbody>
            </table>
         </div>
      </div>
   </div>
</div> -->
<!--
<div class="row-fluid" style = "overflow:auto">
    <div class="col-lg-12" style="min-width: 1500px">
        <div class="box">
            <div class="box-header">
                <span class="title">Duo Queue Orders</span>
            </div>
            <div class="box-content">
                <table class="table table-bordered table-striped table-hover">
                    <thead>
                        <tr>
                            <td>ID</td>
							<td>Buyer</td>
                            <td>Booster</td>
                            <td>Summoner</td>
							<td>Timezone</td>
							<td>Region</td>
							<td>Games needed</td>
							<td>Wins needed</td>
							<td>Coaches needed</td>
                            <td>Wins</td>
                            <td>Losses</td>
                            <td>Start tier</td>
                            <td>Start division</td>
                            <td>Status</td>
							<td>Starting stats</td>
                            <td>Customer paid</td>
                            <td>Booster paid</td>
                            <td>Actions</td>
                        </tr>
                    </thead>
                    <tbody>
                        <?php
					$result = mysql_query("SELECT * FROM duo_order WHERE complete = 0");

					if(mysql_num_rows($result) == 0)
					{
						echo "<tr><td colspan='4'>You don't have any orders.</td></tr>";
					}
					else
					{
						$boosters = array();

						$booster_result = mysql_query("SELECT * FROM user WHERE type = 1 OR type = 2 ORDER BY username");
						
						while($booster_row = mysql_fetch_array($booster_result))
						{
							array_push($boosters, $booster_row);
						}

						while($row = mysql_fetch_array($result))
						{
							$booster_select = "<select name = 'booster' style = 'width: 70px; margin-bottom: 0px;'>";
							
							$x = 0;

							$subresult = mysql_query("SELECT * FROM booster_duo WHERE active <> 0 AND duo_order = ".$row['id']) or die(mysql_error());

							if(mysql_num_rows($subresult) == 0)
							{
								$wins = 0;
								$losses = 0;
								$status = "Pending";
								$booster_select .= "<option selected = 'selected'>None</option>";
								$subrow = array();
								$subrow['booster'] = 0;
								$subrow['active'] = 1;
							}
							else
							{
								$subrow = mysql_fetch_array($subresult);
								$wins = $subrow['wins'];
								$losses = $subrow['losses'];

								if($subrow['active'] == 0)
									$status = "Complete";
								else if($subrow['active'] == 1)
									$status = "Active";
								else if($subrow['active'] == 2)
									$status = "Paused";
								else if($subrow['active'] == 3)
									$status = "Admin reviewing";

								$booster_select .= "<option>None</option>";
							}

							while(isset($boosters[$x]))
							{
								if($subrow['booster'] == $boosters[$x]['id'])
									$booster_select .= "<option value = '".$boosters[$x]['id']."' selected = 'selected'>".$boosters[$x]['username']."</option>";
								else
									$booster_select .= "<option value = '".$boosters[$x]['id']."'>".$boosters[$x]['username']."</option>";
								$x++;
							}
							$booster_select .= "</select>";

							$start_tier_select = "<select name = 'start_tier' style='width: 70px; margin-bottom: 0px;'>";

							if($row['start_tier'] == "Bronze")
								$start_tier_select .= "<option selected = 'selected'>Bronze</option>";
							else
								$start_tier_select .= "<option>Bronze</option>";

							if($row['start_tier'] == "Silver")
								$start_tier_select .= "<option selected = 'selected'>Silver</option>";
							else
								$start_tier_select .= "<option>Silver</option>";

							if($row['start_tier'] == "Gold")
								$start_tier_select .= "<option selected = 'selected'>Gold</option>";
							else
								$start_tier_select .= "<option>Gold</option>";

							if($row['start_tier'] == "Platinum")
								$start_tier_select .= "<option selected = 'selected'>Platinum</option>";
							else
								$start_tier_select .= "<option>Platinum</option>";

							if($row['start_tier'] == "Diamond")
								$start_tier_select .= "<option selected = 'selected'>Diamond</option>";
							else
								$start_tier_select .= "<option>Diamond</option>";

							if($row['start_tier'] == "Challenger")
								$start_tier_select .= "<option selected = 'selected'>Challenger</option>";
							else
								$start_tier_select .= "<option>Challenger</option>";

							$start_division_select = "<select name = 'start_division' style='width: 70px; margin-bottom: 0px;'>";

							if($row['start_division'] == 1)
								$start_division_select .= "<option selected = 'selected'>1</option>";
							else
								$start_division_select .= "<option>1</option>";

							if($row['start_division'] == 2)
								$start_division_select .= "<option selected = 'selected'>2</option>";
							else
								$start_division_select .= "<option>2</option>";

							if($row['start_division'] == 3)
								$start_division_select .= "<option selected = 'selected'>3</option>";
							else
								$start_division_select .= "<option>3</option>";

							if($row['start_division'] == 4)
								$start_division_select .= "<option selected = 'selected'>4</option>";
							else
								$start_division_select .= "<option>4</option>";

							if($row['start_division'] == 5)
								$start_division_select .= "<option selected = 'selected'>5</option>";
							else
								$start_division_select .= "<option>5</option>";

							$region_select = "<select name = 'region' style='width: 70px; margin-bottom: 0px;'>";

							if($row['region'] == "na")
								$region_select .= "<option value = 'na' selected = 'selected'>North America</option>";
							else
								$region_select .= "<option value = 'na'>North America</option>";

							if($row['region'] == "br")
								$region_select .= "<option value = 'br' selected = 'selected'>Brazil</option>";
							else
								$region_select .= "<option value = 'br'>Brazil</option>";

							if($row['region'] == "lan")
								$region_select .= "<option value = 'lan' selected = 'selected'>Latin America North</option>";
							else
								$region_select .= "<option value = 'lan'>Latin America North</option>";

							if($row['region'] == "euw")
								$region_select .= "<option value = 'euw' selected = 'selected'>Europe West</option>";
							else
								$region_select .= "<option value = 'euw'>Europe West</option>";

							if($row['region'] == "eun")
								$region_select .= "<option value = 'eun' selected = 'selected'>Europe East</option>";
							else
								$region_select .= "<option value = 'eun'>Europe East</option>";

							if($row['region'] == "ru")
								$region_select .= "<option value = 'ru' selected = 'selected'>Russia</option>";
							else
								$region_select .= "<option value = 'ru'>Russia</option>";

							if($row['region'] == "tr")
								$region_select .= "<option value = 'na' selected = 'selected'>Turkey</option>";
							else
								$region_select .= "<option value = 'na'>Turkey</option>";

							$region_select .= "</select>";

							$status_select = "<select name = 'status' style='width: 70px; margin-bottom: 0px;'>";

							if($subrow['active'] == 0)
								$status_select .= "<option value = '0' selected = 'selected'>Complete</option>";
							else
								$status_select .= "<option value = '0'>Complete</option>";

							if($subrow['active'] == 1)
								$status_select .= "<option value = '1' selected = 'selected'>Active</option>";
							else
								$status_select .= "<option value = '1'>Active</option>";

							if($subrow['active'] == 2)
								$status_select .= "<option value = '2' selected = 'selected'>Paused</option>";
							else
								$status_select .= "<option value = '2'>Paused</option>";

							if($subrow['active'] == 3)
								$status_select .= "<option value = '3' selected = 'selected'>Reviewing</option>";
							else
								$status_select .= "<option value = '3'>Reviewing</option>";

							echo "<form action = 'change-duo-order.php' method = 'post'><input name = 'order_num' value = '".$row['id']."' type = 'hidden' />";
							echo "<tr><td>".$row['id']."</td>";
							echo "<td style = ''><input name = 'buyer' style = 'margin-bottom: 0px; width: 40px;' value = '".$row['user']."' /></td>";
							echo "<td>".$booster_select."</td>";
							echo "<td><input style = 'width: 40px; margin-bottom: 0px;' name = 'summoner' value = '".$row['summoner']."' /></td>";
							echo "<td><input style = 'width: 40px; margin-bottom: 0px;' name = 'timezone' value = '".$row['timezone']."' /></td>";
							echo "<td>".$region_select."</td>";
							echo "<td><input style = 'width: 20px; margin-bottom: 0px;' name = 'number_of_games' value = '".$row['number_of_games']."' /></td>";
							echo "<td><input style = 'width: 20px; margin-bottom: 0px;' name = 'number_of_wins' value = '".$row['number_of_wins']."' /></td>";
							echo "<td><input style = 'width: 20px; margin-bottom: 0px;' name = 'number_of_coaches' value = '".$row['number_of_coaches']."' /></td>";
							echo "<td><input style = 'width: 25px; margin-bottom: 0px;' name = 'wins' type = 'text' value = '".$wins."' /></td>";
							echo "<td><input style = 'width: 25px; margin-bottom: 0px;' name = 'losses' type = 'text' value = '".$losses."' /></td>";
							echo "<td>".$start_tier_select."</td>";
							echo "<td>".$start_division_select."</td>";
							echo "<td>".$status_select."</td>";
							echo "<td><input name = 'beginning_stats' style = 'width: 40px; margin-bottom: 0px;' value = '".$row['beginning_stats']."' /></td>";
							echo "<td><input name = 'payout' style = 'width: 40px; margin-bottom: 0px;' value = '".$row['payout']."' /></td>";
							echo "<td><input name = 'booster_payout' style = 'width: 40px; margin-bottom: 0px;' value = '".$row['booster_payout']."' /></td>";
							echo "<td style='width:170px'>
							<button style='margin-right:7px' type = 'submit' class=' btn btn-success btn-xs'  />Update</button><a href = 'delete_duo.php?id=".$row['id']."' class = 'btn btn-success btn-xs' onclick = 'check_confirm(event)'>Delete</a></td></tr></form>";
						}
					}
					
				?>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>  -->
<script>
function check_confirm (event)
{
	if(!confirm("Are you sure?"))
	{
		event.preventDefault();
		event.stopPropagation();
		return false;
	}
}
</script>
</div>
</div>
<?php
	include("bottom.php");
?>